package Tree;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Tree
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-10-30  22:10
 * @Description: TODO
 * @Version: 1.0
 */
public class 二叉树左子树之和404 {

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public int sumOfLeftLeaves(TreeNode root) {
        if (root==null){return 0;}
        // 左子树
        int left=sumOfLeftLeaves(root.left);
        // 右子树
        int right=sumOfLeftLeaves(root.right);
        // 中
        int midValue = 0;
        // 表示为的节点的左子树
        if (root.left != null && root.left.left == null && root.left.right == null) {
            midValue = root.left.val;
        }
        int sum=midValue+left+right;
        return sum;
    }
}
